#pragma once

#include <QVector3D>
#include <QObject>
#include <QByteArray>
#include <geometry_msgs/msg/point.hpp>


namespace rviz_custom_plugins 
{


namespace models 
{


class Flyzone
{

public:
    Flyzone() = default;

    ~Flyzone() = default;

    int id = 0;
    geometry_msgs::msg::Point minPoint;
    geometry_msgs::msg::Point maxPoint;
};


inline void to_json(json& j, const Flyzone& zone)
{
    j = json{
        {"id", zone.id},
        {"min", json::array({zone.minPoint.x, zone.minPoint.y, zone.minPoint.z})},
        {"max", json::array({zone.maxPoint.x, zone.maxPoint.y, zone.maxPoint.z})}
    };
}


inline void from_json(const json&j, Flyzone& zone)
{
    zone.id = j.at("id").get<int>();
    auto minArr = j.at("min");
    zone.minPoint.x = minArr[0].get<double>(), 
    zone.minPoint.y = minArr[1].get<double>(), 
    zone.minPoint.z = minArr[2].get<double>();
    auto maxArr = j.at("max");
    zone.maxPoint.x = maxArr[0].get<double>();
    zone.maxPoint.y = maxArr[1].get<double>(), 
    zone.maxPoint.z = maxArr[2].get<double>();

}




class Flyzones
{

public:

    Flyzones() = default;

    Flyzones(const Flyzones& other) : flyzones(other.flyzones) {}

    ~Flyzones() = default;

    std::list<Flyzone> flyzones;

};


inline void to_json(json& j, const Flyzones& flyzones)
{
    j = json{
        {"flyzones", flyzones.flyzones}
    };
}


inline void from_json(const json& j, Flyzones& flyzones)
{
    flyzones.flyzones = j.at("flyzones");
}

}


}


Q_DECLARE_METATYPE(rviz_custom_plugins::models::Flyzones)